<?php

namespace app\admin\model;

use think\Model;


class UserNewsLog extends Model
{





    // 表名
    protected $table = 'user_news_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'send_type_text',
        'created_time_text',
        'updated_time_text'
    ];



    public function getStatusList()
    {
        return ['1' => __('Status 1'), '0' => __('Status 0')];
    }

    public function getSendTypeList()
    {
        return ['2' => __('Send_type 2'),'1' => __('Send_type 1')];
    }

    public function getIsSendList()
    {
        return ['0' => __('不发送'),'1' => __('发送')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSendTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['send_type']) ? $data['send_type'] : '');
        $list = $this->getSendTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreatedTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['created_time']) ? $data['created_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdatedTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['updated_time']) ? $data['updated_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreatedTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdatedTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
